class Node(object):
    pass


class ListNode(Node):
    def __init__(self):
        self.lst = list()

    def append(self, v):
        self.lst.append(v)

    def accept(self, visitor):
        visitor.visitListNode(self)

class BinaryOpNode(Node):
    def __init__(self, left, right, op):
        self.left = left
        self.right = right
        self.op = op

    def accept(self, visitor):
        visitor.visitBinaryOpNode(self)


class ConstValueNode(Node):
    def __init__(self, value):
        self.value = value

    def accept(self, visitor):
        visitor.visitConstValueNode(self)

class NameNode(Node):
    def __init__(self, name):
        self.name = name

    def accept(self, visitor):
        visitor.visitNameNode(self)


class PrintNode(Node):
    def __init__(self, value):
        self.value = value

    def accept(self, visitor):
        visitor.visitPrintNode(self)

class AssignNode(Node):
    def __init__(self, name, value):
        self.name = name
        self.value = value

    def accept(self, visitor):
        visitor.visitAssignNode(self)


class Evaluator(object):
    def __init__(self):
        self.vars_table = dict()
        self._value = 0

    def visit(self, obj):
        obj.accept(self)

    def visitListNode(self, n):
        for e in n.lst:
            self.visit(e)


    def visitBinaryOpNode(self, n):
        self.visit(n.left)
        left = self._value

        self.visit(n.right)
        right = self._value

        if n.op == "+":
            self._value = left + right
        elif n.op == "-":
            self._value = left - right
        elif n.op == "*":
            self._value = left * right
        elif n.op == "/":
            self._value = left // right


    def visitConstValueNode(self, n):
        self._value = n.value

    def visitNameNode(self, n):
        self._value = self.vars_table[n.name]

    def visitAssignNode(self, n):
        name = n.name
        self.visit(n.value)

        self.vars_table[name] = self._value
        
    def visitPrintNode(self, n):
        self.visit(n.value)
        print(self._value)
        
